home *** CD-ROM | disk | FTP | other *** search
- {
- File: StyleMap.p
-
- Contains: Yet another code illustration for the Q&A on "intrinsic styles of a PostScript
- font" in d e v e l o p, Summer 1991, this time in my mother language.
-
- For the sake of simplicity, the font "Times" and the size 36 are hardcoded, and
- the snippet assumes a "Times" FOND can be found in the system. Of course, the
- output looks best if TrueType is present!
-
-
- Written by: Joseph Maurer
-
- Copyright: Copyright © 1991-1999 by Apple Computer, Inc., All Rights Reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
- 7/26/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1
-
-
- }
- program StyleMap;
- uses
- Windows,Quickdraw,Fonts,Events,Menus,TextEdit,Dialogs,Resources;
- var
- gWP: WindowPtr;
-
-
- {------------------------------------------------}
- procedure InitMac;
- begin
- InitGraf(@qd.thePort);
- InitFonts;
- FlushEvents(everyEvent, 0);
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(nil);
- InitCursor;
- end;
-
- {------------------------------------------------}
- procedure InitApp;
- var
- bounds: Rect;
- begin
- SetRect(bounds, 0, 0, 480, 290);
- gWP := NewWindow(nil, bounds, 'Click Mouse to Continue', false, documentProc, WindowPtr(-1), false, 0);
- SetPort(gWP);
- MoveWindow(gWP, 10, 50, true);
- ShowWindow(gWP);
- end;
-
- {------------------------------------------------}
- procedure WaitForButton;
- var
- evt: EventRecord;
- done: Boolean;
- begin
- done := false;
- repeat
- SystemTask;
- if GetNextEvent(keyDownMask + mDownMask, evt) then
- done := (evt.what = mouseDown);
- until done;
- end;
-
- {========================================}
- function CompressStyle (aStyle: Style): Integer; { LaserWriter Reference, p. 32 }
- var
- styleCode: Integer;
- begin
- styleCode := 0;
- if bold in aStyle then
- styleCode := styleCode + 1;
- if italic in aStyle then
- styleCode := styleCode + 2;
- if outline in aStyle then
- styleCode := styleCode + 4;
- if shadow in aStyle then
- styleCode := styleCode + 8;
- if condense in aStyle then
- styleCode := styleCode + 16;
- if extend in aStyle then
- styleCode := styleCode + 32;
- CompressStyle := styleCode; { values 0..47 only: condense/extend mutually exclusive }
- end;
-
-
- {------------------------------------------------}
- function BuildPSFontName (id: Integer; aStyle: Style): Str255;
- label
- 99;
- type
- IntegerPtr = ^Integer;
- FamRecPtr = ^FamRec;
- StylMapTable = record { see LaserWriter Reference p. 28 }
- class: Integer;
- offset: Longint;
- reserved: Longint;
- suffixIndex: packed array[0..47] of SignedByte;
- end;
- StylMapPtr = ^StylMapTable;
- var
- h: Handle;
- p: FamRecPtr;
- offSet: Integer;
- smp: StylMapPtr;
- q: Ptr; { pointer to Style-name table: not a good Pascal structure ...}
- nbOfStrings: Integer; { not used }
- PSName, suffixIndices: Str255;
- i, whichIndex: Integer;
-
- function NthStyleName (index: Integer; q: Ptr): Str255;
- { index 1 => basename, pointed to by q }
- { cf. d e v e l o p Summer 91, p. 100 ! }
- var
- s: Str255;
- begin
- if (index > 1) and (index <= nbOfStrings) then
- begin
- while index > 1 do
- begin
- q := Ptr(ord4(q) + q^ + 1); { assumes q^ = stringlength < 128 ...}
- index := index - 1;
- end;
- BlockMove(q, @s[0], q^ + 1); { assumes q^ = stringlength < 127 ...}
- NthStyleName := s;
- end
- else { FOND corrupted !}
- NthStyleName := '???';
- end;
-
- begin {BuildPSFontName}
- PSName := '';
- TextFace(aStyle);
- h := GetResource('FOND', id);
- if h = nil then
- goto 99; { a reminiscence of AppleSoft }
- HLock(h);
- p := FamRecPtr(h^);
- offSet := p^.ffStylOff;
- if offSet = 0 then { no style-mapping table }
- goto 99; { again ?! }
- smp := StylMapPtr(ord4(p) + offSet);
- q := Ptr(ord4(smp) + SizeOf(StylMapTable)); { style-name table follows style-mappingTable}
- nbOfStrings := IntegerPtr(q)^; { for range checking in "NthStyleName" above }
- q := Ptr(ord4(q) + 2); { now pointing to basename of font }
- BlockMove(q, @PSName, q^ + 1); { basename of font; assumes length < 128 }
- whichIndex := smp^.suffixIndex[CompressStyle(aStyle)];
- if whichIndex > 1 then
- begin
- suffixIndices := NthStyleName(whichIndex, q);
- for i := 1 to ord(suffixIndices[0]) do
- PSName := concat(PSName, NthStyleName(ord(suffixIndices[i]), q));
- end;
- HUnlock(h);
- 99:
- BuildPSFontName := PSName;
- end; {BuildPSFontName}
-
-
- {------------------------------------------------}
- procedure Test;
- var
- fontName: Str255;
- familyID: Integer;
- aStyle: Style;
- begin
- fontName := 'Times';
- GetFNum(fontName, familyID);
- TextFont(familyID);
- TextSize(36);
-
- aStyle := []; { plain }
- MoveTo(30, 60);
- DrawString(BuildPSFontName(familyID, aStyle));
-
- aStyle := [bold];
- MoveTo(30, 120);
- DrawString(BuildPSFontName(familyID, aStyle));
-
- aStyle := [italic];
- MoveTo(30, 180);
- DrawString(BuildPSFontName(familyID, aStyle));
-
- aStyle := [bold, italic];
- MoveTo(30, 240);
- DrawString(BuildPSFontName(familyID, aStyle));
- end;
-
- {------------------------------------------------}
- begin
- InitMac;
- InitApp;
- Test;
- WaitForButton;
- end.
- {------------------------------------------------}